package com.app.oasystem.controller;

import com.app.oasystem.dto.ActionResult;
import com.app.oasystem.dto.PageGridDto;
import com.app.oasystem.dto.TableDto;
import com.app.oasystem.entity.Record;
import com.app.oasystem.service.impl.RecordServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 86+
 * @data 2021-04-13
 */

@RestController
@RequestMapping("/record")
public class RecordController {
    @Resource
    RecordServiceImpl recordService;

    @PostMapping("/all")
    public TableDto getUserList(@RequestBody PageGridDto pageGridDto) {
        return recordService.getRecordList(pageGridDto);
    }

    /**
     * 打卡上班
     */
    @GetMapping("/up/{id}")
    public ActionResult up(@PathVariable("id") Integer id) {
        return (ActionResult) recordService.up(id);
    }

    /**
     * 打卡下班
     */
    @GetMapping("/down/{id}")
    public ActionResult down(@PathVariable("id") Integer id) {
        return (ActionResult) recordService.down(id);
    }

    /**
     * 根据id获取Record信息
     */
    @GetMapping("/{id}")
    public Object getRecordInfoById(@PathVariable("id") Integer id) {
        return new ActionResult(recordService.getRecordInfoById(id));
    }

    /**
     * 获取Record信息
     */
    @GetMapping("/n")
    public Object getRecordInfoByName(@RequestParam("name") String name) {
        return new ActionResult(recordService.getRecordInfoByName(name));
    }

    /**
     * 新增Record
     */
    @PostMapping("/add")
    public Object insertRecord(@RequestBody Record record) {
        return new ActionResult(recordService.insertRecord(record));
    }

    /**
     * 更新Record
     */
    @PostMapping("/update")
    public Object updateRecord(@RequestBody Record record) {
        return new ActionResult(recordService.updateRecord(record));
    }

    /**
     * 根据id删除Record
     */
    @DeleteMapping("/{id}")
    public Object delRecord(@PathVariable("id") Integer id) {
        return new ActionResult(recordService.deleteRecord(new Record().setId(id)));
    }
}

